from export.export import export_to_excel
from whatweb.whatweb import WhatWeb
from httpx.httpx import HTTPX
from config.settings import PACKAGE_PATH
from utils.excel import get_subdomains_from_excel
import pandas as pd
from wafw00f.main import scan as waf_scan


def complete_alive_domain_infos(save_path):
    domains = get_subdomains_from_excel(save_path)
    httpx_exec_path = PACKAGE_PATH / 'thirdparty/httpx'
    httpx = HTTPX(httpx_exec_path, domains)
    httpx.run(save_path, is_save=False)
    httpx_result = httpx.httpx.results
    httpx_results = pd.DataFrame(httpx_result)
    whatweb = WhatWeb(('/home/john/evo/Data/备份/project/WhatWeb/whatweb', ))
    whatweb.run(httpx.results)
    waf_result = waf_scan(httpx.results)
    waf_results = pd.DataFrame(waf_result)
    whatweb_results = pd.DataFrame(whatweb.parse_results)
    alive_domain_results = pd.merge(left=httpx_results,
                                    right=whatweb_results,
                                    how='left',
                                    on='url')
    alive_domain_results = pd.merge(left=alive_domain_results,
                                    right=waf_results,
                                    how='left',
                                    on='url')
    export_to_excel(alive_domain_results, sheet_name='存活域名', xlsx_name='test',
                    columns_dict=httpx.httpx.columns_dicts, save_path=save_path)
